package com.itany.corejava.code06_数组;

import java.util.Arrays;

/**
 * @author: 石小俊
 * @date: 2023年03月03日 15:55
 * @version: 1.0
 */
public class Test02_Arrays工具类 {

    public static void main(String[] args) {
        sortTest();
    }

    public static void toStringTest(){
        int[] numbers = {1,11,3,21};
        System.out.println(numbers);
        for(int i : numbers){
            System.out.println(i);
        }
        System.out.println("["+numbers[0]+", "+numbers[1]+", "+numbers[2]+", "+numbers[3]+"]");
        System.out.println(Arrays.toString(numbers));
    }

    public static void sortTest(){
        // 如果数组是一个数值型数组, 则按照数值大小进行排序
        int[] numbers = {1,12,2,13,4,21};
        // double[] numbers = {12,15,3.14,3.15,5,1.2};
        Arrays.sort(numbers);
        System.out.println(Arrays.toString(numbers));

        // 如果数组是一个字符串, 则按照字典顺序进行升序排序
        String[] numbers2 = {"12","1","22","3","35","5"};
        Arrays.sort(numbers2);
        System.out.println(Arrays.toString(numbers2));

        String[] names = {"jack","tom","admin","root","alice"};
        Arrays.sort(names);
        System.out.println(Arrays.toString(names));
    }
}
